<template>
  <div>
    <ul>
      <li>
        <router-link to="/contacts/allcontacts">All_contacts</router-link>
      </li>
      <li>
        <router-link to="/contacts/alice">Alice</router-link>
      </li>
      <li>
        <router-link to="/contacts/bob">Bob</router-link>
      </li>
    </ul>
    <button @click="btn">随机显示</button>

    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data () {
    return {
      arr: ['/contacts/allcontacts', '/contacts/alice', '/contacts/bob']
    }
  },
  methods: {
    btn () {
      let targetPath = this.arr[Math.floor(Math.random() * this.arr.length)];
      if (this.$router.path !== targetPath) {
        this.$router.replace(targetPath)
      }
    }
  }
}
</script>

<style>
</style>